package com.gisuni.sddc.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import com.gisuni.sddc.model.BaseUser;

@IocBean
public class BaseUserDao {
	@Inject
	private Dao dao;  //=OdbcCommon.getGISDao();
	
 
	public BaseUser userupdata(BaseUser baseUser){
		dao.update(baseUser);
		return baseUser;
	}
 
    public Boolean updateBaseUser(String updateSql ){
    	Boolean result = false;
    	Sql sql = Sqls.create(updateSql);
	    sql.setCallback(new SqlCallback() {
			public Object invoke(Connection conn, ResultSet rs, Sql sql)
					throws SQLException {
				return true;
			}
		});
	    dao.execute(sql);
	    return  sql.getObject(Boolean.class );
//	   s return "操作失败，请重试";
    }
 
	public String queryBaseUserAll(int from,int to,String selectSql){
		Sql sql = Sqls.create(selectSql);
	    sql.setCallback(new SqlCallback() {
			public Object invoke(Connection conn, ResultSet rs, Sql sql)
					throws SQLException {
				JSONArray result=new JSONArray();
			     while (rs.next()){
			    	 JSONObject ret=new JSONObject();
			    	 	ret.put("companyId", rs.getString("COMPANYID"));
			    		ret.put("businessId", rs.getString("BUSINESSID"));
			    		ret.put("developId", rs.getString("DEVELOPID"));
			    	    ret.put("name", rs.getString("NAME"));
 
			    	 ret.put("id",rs.getString("ID"));
			    	 ret.put("loginname", rs.getString("LOGINNAME"));
			    	 result.put(ret);
			     }
				return result.toString();
			}
		});
	    dao.execute(sql);
	    return  sql.getObject(String.class);
	}
 
	public int queryBaseUsertotal(String str){
		int num = dao.count(BaseUser.class,Cnd.wrap(str));
		return num;
	}
 
}
